package com.system.controller.exam;

import com.common.core.controller.BaseController;
import com.common.core.domain.Result;
import com.common.core.domain.TableDataInfo;
import com.system.domain.exam.dto.ExamAddDTO;
import com.system.domain.exam.dto.ExamEditDTO;
import com.system.domain.exam.dto.ExamQueryDTO;
import com.system.domain.exam.dto.ExamQuestionAddDTO;
import com.system.domain.exam.vo.ExamDetailVO;
import com.system.service.exam.ExamService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exam")
@Tag(name = "竞赛管理API")
public class ExamController extends BaseController {
    @Resource
    ExamService examService;

    /**
     * 获取竞赛列表
     *
     */
    @GetMapping("/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return getTableData(examService.list(examQueryDTO));
    }

    /**
     * 新增竞赛
     *
     */
    @PostMapping("/add")
    public Result<Void> add(@RequestBody ExamAddDTO examAddDTO){
        return toResult(examService.add(examAddDTO));
    }

    /**
     * 为竞赛添加题目
     *
     */
    @PostMapping("/question/add")
    public Result<Void> questionAdd(@RequestBody ExamQuestionAddDTO examQuestionAddDTO){
        return toResult(examService.questionAdd(examQuestionAddDTO));
    }

    /**
     * 为竞赛删除题目
     *
     */
    @DeleteMapping("/question/delete")
    public Result<Void> questionDelete(Long examId,Long questionId){
        return toResult(examService.questionDelete(examId,questionId));
    }

    /**
     * 获取编辑页面的竞赛详情
     *
     */
    @GetMapping("/detail")
    public Result<ExamDetailVO> detail(Long examId){
        return Result.success(examService.detail(examId));
    }

    /**
     * 对竞赛基本信息进行编辑
     *
     */
    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody ExamEditDTO examEditDTO){
        return toResult(examService.edit(examEditDTO));
    }

    /**
     * 删除竞赛
     *
     */
    @DeleteMapping("/delete")
    public Result<Void> delete(Long examId){
        return toResult(examService.delete(examId));
    }

    /**
     * 发布竞赛
     *
     */
    @PutMapping("/publish")
    public Result<Void> publish(Long examId){
        return toResult(examService.publish(examId));
    }

    /**
     * 撤销发布竞赛
     *
     */
    @PutMapping("/cancelPublish")
    public Result<Void> cancelPublish(Long examId){
        return toResult(examService.cancelPublish(examId));
    }
}
